<template>
    
  <div class="fenlei">
      <Search></Search>
    <van-tree-select
      height="100%"
      :items="speciesList"
      :main-active-index.sync="active"
        @click-nav="onchange"
    >

    <template #content>
        <div v-for="(x,y) in speciesList" :key="y" class="list-x">
                <div v-if="active === x.active" class="list-y">
                        
                        <div class="" v-for="(l,i) in list" :key="i">
                            
                            <img :src="l.img" alt="">
                             {{l.type}}
                        </div>
                </div>
        </div>
    </template>
    </van-tree-select>
  </div>
</template>

<script>
import axios from 'axios'
import {speciesList} from '@/utils/classification.js'
export default {
   data() {
    return {
      active: 0,
      speciesList:speciesList,
      names:speciesList.name,
      list:[],
      abab:'',
    };
   },
   mounted(){
      axios.get("http://localhost:3000/cheap")
        .then(res=>{
        //    console.log(res);
            this.list = res.data
        })
   },
   methods:{
     onchange(v){
        axios.get("http://localhost:3000/"+speciesList[v].name)
        .then(res=>{
        //    console.log(res);
            this.list = res.data
        })
        // console.log(speciesList[v].name);
     }
   }
}

</script>

<style lang="scss" scoped>
.list-x{
   
    .list-y{
        width: 100%;
         display: flex;
            flex-wrap:wrap ;
            justify-content: space-around;
            align-items: center;
            text-align: center;
            div{
                margin-bottom: 20px;
            }
    }
}
  .fenlei{
    margin-top: 60px;
    height: 100%;
    img{
       width:100px;
       height: 100px;
    }
    .van-sidebar { 
            position: fixed;
            left: 0;
            top: 50px;
            bottom: 0;
            width: 100px;
            background: #fff;
            overflow-x: hidden;
            overflow-y: scroll;
    }
  }
  .van-tree-select__content{
    position: fixed;
    top: 50px;
    left: 100px;
    right: 0;
    bottom: 10px;
    padding: 10px;
    overflow-x: hidden;
    overflow-y: scroll;
  }
</style>